package com.apesay.service.base;

import com.alibaba.fastjson.JSONObject;
import com.apesay.exception.ServiceException;
import com.apesay.utils.Constant;
import com.apesay.utils.MongoCondition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ClientService {
	Logger logger = LoggerFactory.getLogger(ClientService.class);
	@Autowired
	private APIService apiService;
	@Autowired
	private FunctionsService functionsService;
	private static String inc_model = null;

	public JSONObject getObjectById(String model,String id)  {
		return apiService.get(model,id);
	}

	@SuppressWarnings("deprecation")
	public JSONObject add(String model,JSONObject data)  {
		return apiService.save(model,data.toJSONString());
	}

	@SuppressWarnings("deprecation")
	public JSONObject update(String model,String id, JSONObject data)  {
		return apiService.update(model,data.toJSONString(),id);
	}

	public JSONObject delete(String model,String id)  {
		return apiService.delete(model,id);
	}

	public JSONObject find(String query, String fields, String orderBy,String model, int numToSkip, int batchSize)
			 {
		return functionsService.find(query,fields,orderBy,model,numToSkip,batchSize);
	}

	public List<?> distinct(String query, String fieldName,String model)  {
		return functionsService.distinct(query,fieldName,model);
	}

//	public long inc(String colume) {
//		JSONObject update = new JSONObject();
//		update.put(colume,1);
//		JSONObject data = new JSONObject();
//		data.put(MongoCondition.INC.getVal(),update);
//		if (null == inc_model) {
//			JSONObject inc_model = apiService.save(, data.toJSONString());
//			inc_model = inc_model.getJSONObject(Constant.OBJECTID);
//		} else {
//			apiService.update()
//		}
//	}
}
